<?php

require_once($baseDir . '/lib/model/Friend.php');

class FriendList {

	private $oneKey;

	private function getFriendList() {
		return array(
			new Friend("Александр", "1985", "alex@mail.com"),
			new Friend("Юрий", "1987", "yury@gmail.com"),
			new Friend("Алексей", "1989", "alexey@yahoo.com"),
		);
	}

	private function getIndexedList() {
		$list = array();
		foreach($this->getFriendList() as $val) {
			$list[$val->getKey()] = $val;
		}
		return $list;
	}

	public function setKey($key) {
		$this->oneKey = $key;
	}

	public function fetch() {

		$aFriend = $this->getIndexedList();
		return ($this->oneKey) ? $aFriend[$this->oneKey] : $aFriend;
	}
}